package com.ourchem.web.controller.system;

import com.ourchem.common.core.domain.entity.SysUser;
import com.ourchem.system.service.ISysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;
import com.ourchem.common.core.controller.BaseController;
import com.ourchem.common.core.domain.AjaxResult;
import com.ourchem.common.core.domain.model.RegisterBody;
import com.ourchem.framework.web.service.SysRegisterService;
import com.ourchem.system.service.ISysConfigService;

/**
 * 注册验证
 *
 * @author ourchem
 */
@RestController
public class SysRegisterController extends BaseController
{

    @Autowired
    private SysRegisterService registerService;

    @Autowired
    private ISysConfigService configService;

    @PostMapping("/register")
    public AjaxResult register(@RequestBody RegisterBody user)
    {
        if (!("true".equals(configService.selectConfigByKey("sys.account.registerUser"))))
        {
            return error("当前系统没有开启注册功能！");
        }
        String msg = registerService.register(user);
        return StringUtils.isEmpty(msg) ? success() : error(msg);
    }

/*    @GetMapping("/email")
    public AjaxResult email(@RequestParam String email)
    {
        String msg = new String();
        if (!StringUtils.isEmpty(email)){
            SysUser sysUser = new SysUser();
            sysUser.setEmail(email);
            msg = UserService.checkEmailUnique(sysUser);
        }else {
            throw new RuntimeException("没有输入邮箱");
        }
        return StringUtils.isEmpty(msg) ? success() : error(msg);
    }*/

}
